<?php require_once('connections/con_gl.php'); ?>
<?php

cekAkses($_SESSION[akses],"KR-1-1");
mysql_select_db($database_con_gl, $con_gl);
$query_kontak = "SELECT id, nama, type, tcustomer FROM gl_kontak where gl_kontak.type='Customer' AND status='AKTIF' ORDER BY type, nama ASC";
$kontak = mysql_query($query_kontak, $con_gl) or die(mysql_error());
$row_kontak = mysql_fetch_assoc($kontak);
$totalRows_kontak = mysql_num_rows($kontak);

unset($_SESSION['kendaraan']);
unset($_SESSION['txtkendaraan']);
unset($_SESSION['hargasatuan']);
unset($_SESSION['diskon']);
unset($_SESSION['total']);
unset($_SESSION['transaksi']);
unset($_SESSION['subtotal']);
unset($_SESSION['pajak']);
unset($_SESSION['grandtotal']);

function romawi($bulan){switch($bulan){case '01':$rom="I";break;case '02':$rom="II";break;case '03':$rom="III";break;case '04':$rom="IV";break;case '05':$rom="V";break;case '06':$rom="VI";break;case '07':$rom="VII";break;case '08':$rom="VIII";break;case '09':$rom="IX";break;case '10':$rom="X";break;case '11':$rom="XI";break;case '12':$rom="XII";break;}return $rom;}

function getidkontrak(){list($a)=mysql_fetch_row(mysql_query("select max(no) from gl_kontrak"));$no=explode("/",$a);$now=intval($no[0]);if($now<10)return "00".($now+1);if($now<100 && $now>9 )return "0".($now+1);if($now<1000 && $now>99 )return ($now+1);}
// ---

mysql_select_db($database_con_gl, $con_gl);

$query_gudang = "SELECT id, gudang FROM gl_gudang";

if(!strstr($_SESSION[akses],'A-1-4')) {

	$query_gudang .= " where id='$_SESSION[lokasi]'";

}

$query_gudang .=" ORDER BY gudang ASC";

$gudang = mysql_query($query_gudang, $con_gl) or die(mysql_error());

$row_gudang = mysql_fetch_assoc($gudang);

$totalRows_gudang = mysql_num_rows($gudang);



mysql_select_db($database_con_gl, $con_gl);

$query_satuan = "SELECT id, satuan FROM gl_satuan ORDER BY satuan ASC";

$satuan = mysql_query($query_satuan, $con_gl) or die(mysql_error());

$row_satuan = mysql_fetch_assoc($satuan);

$totalRows_satuan = mysql_num_rows($satuan);



mysql_select_db($database_con_gl, $con_gl);

$query_kelom = "select a.tipekendaraan, b.nopolisi from gl_tipekendaraan a, gl_masterkendaraan b where a.id = b.tipekendaraan AND b.tersedia='1' order by a.tipekendaraan, b.nopolisi";

$kelom = mysql_query($query_kelom, $con_gl) or die(mysql_error());

$row_kelom = mysql_fetch_assoc($kelom);

$totalRows_kelom = mysql_num_rows($kelom);



mysql_select_db($database_con_gl, $con_gl);

$query_klas = "SELECT kd, klasifikasi, keterangan, neraca, ruglab, tipe FROM gl_klas where tipe = 6 ORDER BY kd,klasifikasi ASC";

$klas = mysql_query($query_klas, $con_gl) or die(mysql_error());

$row_klas = mysql_fetch_assoc($klas);

$totalRows_klas = mysql_num_rows($klas);

// salesman
mysql_select_db($database_con_gl, $con_gl);
$query_salesmen = "SELECT gl_kontak.id, gl_kontak.nama FROM gl_kontak WHERE gl_kontak.type='Karyawan' AND gl_kontak.tkaryawan='sales' order by nama";
$salesmen = mysql_query($query_salesmen, $con_gl) or die(mysql_error());
$row_salesmen = mysql_fetch_assoc($salesmen);
$totalRows_salesmen = mysql_num_rows($salesmen);


mysql_select_db($database_con_gl, $con_gl);

$query_def_ak = "SELECT gl_company.a_piu FROM gl_company";

$def_ak = mysql_query($query_def_ak, $con_gl) or die(mysql_error());

$row_def_ak = mysql_fetch_assoc($def_ak);

$totalRows_def_ak = mysql_num_rows($def_ak);


$totdeb = 0;

$totkre = 0;

?>

<link rel="stylesheet" type="text/css" href="css/ui.datepicker.css"/>
<style>
#cusinfo tr td {
	font-size:10px;	
}
</style>
<script type="text/javascript" src="js/ajax_data.js"></script>
<script type="text/javascript" src="js/ui.datepicker.js"></script>
<script type="text/javascript">
<!--
$(function(){
	$('.calendar').datepicker({
		appendText : "",
		dateFormat : 'yy/mm/dd'
	});
});
</script>

<script type="text/javascript">
$(document).ready(function() {
	$().ajaxStart(function() {
		$('#loading').show();
		$('#result').hide();
	}).ajaxStop(function() {
		$('#loading').hide();
		$('#result').fadeIn('slow');
	});
	$('#add').submit(function() {
		$.ajax({
			type: 'POST',
			url: $(this).attr('action'),
			data: $(this).serialize(),
			success: function(data) {
				$('#result').html(data);
			}
		})
		return false;
	});
  $('#result').click(function(){
  $(this).hide();
  });
})
</script>

<script type="text/javascript">
function sendRespondKontak(tip) {
	var ajaxRequest;  // The variable that makes Ajax possible!
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('divKontak');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
		if (ajaxRequest.readyState == 3) {
			var ajaxDisplay = document.getElementById('divKontak');
			ajaxDisplay.innerHTML = "<img src='images/ajax-loader.gif' />";
		}
	}
	ajaxRequest.open("GET", "include/send_respondkontak.php", true);
	ajaxRequest.send(null);	
}
</script>
<div id="loading" style="display:none;"><img src="images/loading.gif" alt="loading..." /></div>
<div id="result" style="display:none;"></div>
<h1>Tambah Data SPK</h1>
<div id="divDetail"> </div>
<form action="proses/kontrak.php?act=add" method="post" name="add" id="add">

  <table width="98%" border="0" align="center" cellpadding="5" cellspacing="0" class="datatable">

    <tr valign="top">
      <td align="right">Tanggal :</td>
      <td><label>
        <input name="tanggal" type="text" class="calendar" id="tanggal" value="<?php echo date("Y/m/d");?>" size="12" maxlength="12"/>
      </label></td>

      <td width="12%" align="right">Lokasi Kantor :</td>

      <td><select name="gudang" id="gudang" style="width:180px;">
        <?php

do {  

?>
        <option value="<?php echo $row_gudang['id']?>"><?php echo $row_gudang['gudang']?></option>
        <?php

} while ($row_gudang = mysql_fetch_assoc($gudang));

  $rows = mysql_num_rows($gudang);

  if($rows > 0) {

      mysql_data_seek($gudang, 0);

	  $row_gudang = mysql_fetch_assoc($gudang);

  }

?>
      </select></td>
    </tr>

    <tr>
      <td align="right" valign="top">No. SPK :</td>
      <td valign="top"><div id="refDiv">
          <label>
          <?php list($kodecabang) = mysql_fetch_row(mysql_query("select kodecabang from gl_gudang where id = '$_SESSION[lokasi]'")); ?>
          <input name="noreferensi" type="text" id="noreferensi" value="<?php echo getidkontrak()."/SP/".$kodecabang."/corp-BDP/".romawi(date("m"))."/".date("Y"); ?>" size="30" maxlength="100" readonly="readonly">
          </label>
      </div></td>

      <td align="right" valign="top">Salesman : </td>
      <td valign="top"><select name="recipient" id="recipient" style="width:180px;">
          <?php

do {  

?>
          <option value="<?php echo $row_salesmen['id'];?>" <?php if($_session[kontakid] == $row_salesmen['id']) { ?>selected="selected"<?php } ?>><?php echo $row_salesmen['nama']?></option>
          <?php

} while ($row_salesmen = mysql_fetch_assoc($salesmen));

  $rows = mysql_num_rows($salesmen);

  if($rows > 0) {

      mysql_data_seek($salesmen, 0);

	  $row_salesmen = mysql_fetch_assoc($salesmen);

  }

?>
      </select></td>
    </tr>

    <tr>
      <td align="right" valign="top">No PO : </td>
      <td valign="top"><input name="nopo" type="text" id="nopo" size="30" maxlength="100" /></td>
      <td align="right" valign="top">Durasi Kontrak :</td>
      <td valign="top"><label>
        <input name="durasi" id="durasi" onchange="genAkhirKontrak();" size="5" maxlength="8"/>
        Bulan</label></td>
    </tr>
    <tr>

      <td align="right" valign="top">Bengkel Rekanan:</td>
      <td valign="top">
	  <!-- Added by suwondo -->
	  <input type="hidden" name="dari" id="dari" />
	  <input type="text" name="qtxt" id="qtxt" placeholder="Cari Customer ..." size="28" readonly style="background-color:#fff;border:1px solid #999; height:16px;" onclick="NewWindow('index.php?component=kontak&amp;task=listcustomercorp&amp;open=window','name','825','450','yes');return false" />
	  <?php if(strstr($_SESSION['akses'],"DD-2-1")) { ?><a href="index.php?component=kontak&task=add&ref=Customer&open=window" onclick="NewWindow(this.href,'name','825','525','yes');return false"><img src="images/add_.png" hspace="2" border="0" style="position:absolute;" /></a><?php } ?></td>

      <td align="right" valign="top">Pembayaran :</td>
      <td valign="top"><label>/
        <input name="pembayaran" id="pembayaran" size="3" maxlength="5" />
        Bulan</label></td>
    </tr>

    <tr>
      <td align="right" valign="top">&nbsp;</td>
      <td valign="top">&nbsp;</td>
      <td align="right" valign="top">Keterangan :</td>
      <td valign="top"><div id="divKeterangan">
        <textarea name="keterangan" cols="40" rows="2" id="keterangan">Daftar Transaksi Jurnal Penjualan</textarea>
        <input name="cid" type="hidden" id="cid" value=""/>
      </div></td>
    </tr>

    <tr>

      <td colspan="4" align="right">
		<div id="ajaxDiv"><?php include "detail.php"; ?></div>	</td>
    </tr>

    <tr>

      <td align="right">&nbsp;</td>

      <td colspan="3" align="right"><input name="page" type="hidden" id="page" value="jual" />

      <input name="jenis" type="hidden" id="jenis" value="7" />

          <label>

          <input name="Save" type="submit" id="Save" value="Simpan Kontrak" />
        </label></td>
    </tr>
  </table>

  <input type="hidden" name="MM_update" value="add" />

  <input type="hidden" name="MM_insert" value="add" />

</form>

